# -*- coding: utf-8 -*-
from odoo import models, api, fields, tools
from odoo.exceptions import UserError
import re


class pest(models.Model):

    _name = "datcent.pest"
    _description = "虫害"
    _table = "datcent_pest"
    _order = "sequence"
    _inherit =  ['mail.thread', 'mail.activity.mixin', 'image.mixin']

    sequence = fields.Integer(string="排序",translate = 0)
    name = fields.Char(string="虫害名称",translate = 0)
    alias = fields.Char(string="别名",translate = 0)
    latin_name = fields.Char(string="拉丁文名",translate = 0)
    english_name = fields.Char(string="英文名",translate = 0)
    family_genus_id = fields.Many2one(string="科属种",comodel_name = 'datcent.family_genus',translate = 0)
    pest_category_id = fields.Many2one(string="虫害类型",comodel_name = 'datcent.diseases_pest_category',translate = 0)
    crop_ids = fields.Many2many(string="为害作物",comodel_name = 'datcent.crop',translate = 0)
    damage_site = fields.Char(string="为害部位",translate = 0)
    region_ids = fields.Many2many(string="分布区域",comodel_name = 'setcent.region',translate = 0)
    pathogenic = fields.Html(string="形态特征",translate = 0)
    habits = fields.Html(string="生活习性",translate = 0)
    harmful_symptoms = fields.Html(string="为害症状",translate = 0)
    environment = fields.Html(string="环境关系",translate = 0)
    preventive_management = fields.Html(string="防治措施",translate = 0)
    detail_contents = fields.Html(string="详细说明",translate = 0)
    image = fields.Binary(string="相关照片",translate = 0)
    attachment = fields.Many2many(string="相关附件",comodel_name = 'ir.attachment',translate = 0)
    state = fields.Selection(string="状态",selection = [('1', '草稿'), ('2', '提交'), ('3', '审核')],default='1',translate = 0)

    def button1(self):
        if self.state == '1':
            self.write({'state': '2'})
        # 审核
    def button2(self):
        if self.state == '2':
            self.write({'state': '3'})
        # 退回
    def button3(self):
        if self.state == '2':
            self.write({'state': '1'})

        # 反审核
    def button4(self):
        if self.state == '3':
            self.write({'state': '2'})
